<template>
    <div class="ec-app-container">
        <!-- 查询条件 -->
        <div class="filter-container">
            <el-form label-width="90px">
                <el-row :gutter="10">
                    <el-col :span="6">
                        <el-form-item label="视频标题：" >
                            <el-input v-model="listQuery.title" placeholder="视频标题"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="text-center">
                        <el-button type="" class="border-4C7FD7 color-4C7FD7" icon="el-icon-search" @click="searchList">查询</el-button>
                        <el-button class="border-4C7FD7 color-4C7FD7" @click="resetSearch">重置</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <!-- table -->
        <div>
            <div class="mt-30">
                <el-button class="filter-item" type="primary" @click="addVideo">新增</el-button>
            </div>
            <div class="mt-20">
                <el-table
                        v-loading="listLoading"
                        :data="list"
                        border
                        fit
                        highlight-current-row
                        @selection-change="handleSelectionChange"
                        style="width: 100%;">
                    <el-table-column
                            type="selection"
                            width="55"/>
                    <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
                        <template slot-scope="scope">
                            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">发布</el-button>
                            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="楼旁" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.buildingName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="视频标题" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.cityName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="视频地址" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.buildingStatus }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="播放次数" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.id }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="创建人" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.id }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="创建时间" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.id }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="发布状态" prop="id" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.id }}</span>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="searchList" />
        </div>
        <!-- 新增修改 -->
        <el-dialog :visible.sync="dialogFormVisible" title="新增视频" width="450px">
            <el-form ref="videoForm" :model="video" :rules="videoRules" label-width="110px">
                <el-row>
                    <el-form-item label="视频封面：" prop="roleName">
                        <el-input v-model="video.videoCover"/>
                    </el-form-item>
                    <el-form-item label="视频标题：" prop="roleName">
                        <el-input v-model="video.videoTitle"/>
                    </el-form-item>
                    <el-form-item label="视频描述：" prop="roleName">
                        <el-input v-model="video.videoDesc"/>
                    </el-form-item>
                    <el-form-item label="视频：" prop="roleName">
                        <el-input v-model="video.videoUrl"/>
                    </el-form-item>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="onCancel">取 消</el-button>
                <el-button type="primary" :loading="btnLoading" @click="onSubmit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import Pagination from '@/components/Pagination' // Secondary package based on el-pagination、
    import { mixin } from '@/common/mixins/mixin'
    import common from '@/api/common'
    import { saveNewMedia } from '@/api'
    export default {
        name: 'Project',
        components: {
            Pagination
        },
        mixins: [mixin],
        data() {
            return {
                listLoading: false,
                total: 0,
                listQuery: {
                    title: '',
                    pageSize: 10,
                    pageNum: 1
                },
                list: [],
                buildingStatus:common.buildingStatus,
                dialogFormVisible: false,
                btnLoading: false,
                multipleSelection: [],
                video: {
                    'videoCover': '',
                    'videoTitle': '',
                    'videoDesc': '',
                    'videoUrl': '',
                    'releaseStatus': 1,
                    'dataType': {
                        'name': '视频管理'
                    }
                }
            }
        },
        created() {

        },
        methods: {
            getList() {
                alert('查询')
            },
            searchList() {
                alert('搜索')
            },
            // 新增楼盘
            addVideo() {
                this.dialogFormVisible = true
            },

            // 选择复选框
            handleSelectionChange(val) {
                this.multipleSelection = val
                // this.userIds = _.map(this.multipleSelection, 'userId')
            },
            onSubmit() {
                const str = this.roleId ? '修改' : '新增'
                this.$confirm(`此操作将${str}角色, 是否继续?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.btnLoading = true
                    const building = {
                        obj: this.video
                    }
                    saveNewMedia(building).then((res) => {
                        this.$message({
                            type: 'success',
                            message: `楼盘${str}成功!`
                        })
                    })

                })
            },
            onCancel() {
                this.dialogFormVisible = false
            }
        }
    }
</script>

<style scoped>

</style>